<template>
    <div id="collectAll">
        <scroller snappingHeight="10" class="scroller" :on-refresh="refresh" :on-infinite="infinite" ref="my_scroller">
            <div class="receiveitem" v-for="(item,index) in applyLists" :key="index">
                <div class="userinfo">
                    <p>我申请加入{{item.cappcompany}}</p>
                </div>
                <div v-if="!item.dconfirmdate" class="icons" @click="beforeSure(item)">
                    <a href="javascript:0;" class="fo-right"><i class="iconfont icon-yiguanzhu"></i><label >撤销申请</label></a>
                </div>
            </div>
        </scroller>
         <!-- 确认提示框 -->
        <el-dialog
            id="tosureExch"
            :visible.sync="sureVisible"
            width="80%"
            style="margin-top:15vh">
            <span>确认要取消申请吗？</span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="sureVisible = false">取 消</el-button>
                <el-button type="primary" @click="toSureDel">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 确认提示框结束 -->
    </div>
</template>

<script>
const perPage = 10;
import {myselfList,delapply} from './apply.js'
import {baseUrl} from '../../../../config/env.js'
export default {
    data(){
        return {
            sureVisible:false,
            nowPage:1,
            sure:'',
            applyLists:[],
            baseUrl:{baseUrl}
        }
    },
    methods:{
        async infinite(done) {
                let self = this
                let cards = [];
                let responseData = myselfList();
                await responseData.then((res)=>{
                                                if(res.result == 1){
                                                    let lists = res.data.reverse();
                                                    lists.forEach( (item,key) => {
                                                        cards.push(item)
                                                    })
                                                }
                                            })
                let pageNum = Math.ceil(cards.length/perPage);
                if(self.nowPage>pageNum){
                    self.$refs.my_scroller.finishInfinite(2);
                    return;
                }else{
                    for (let i = (self.nowPage-1)*perPage; i < perPage*self.nowPage; i++) {
                        if(cards[i]){
                            self.applyLists.push(cards[i]);
                        }
                    }
                    self.nowPage++;
                    done()
                }
            

            },
        refresh(done) {
            done()
        },
        beforeSure(list){
            this.sureVisible = true;
            this.sure = list
        },
        //确认删除
        toSureDel(){
            if(sessionStorage.sid){
                let self = this;
                let responseData = delapply(self.sure.id);
                responseData.then((res)=>{
                                            if(res.result==1){
                                                self.sureVisible = false;
                                                let index = self.applyLists.indexOf(self.sure);
                                                self.applyLists.splice(index,1)
                                                self.$message({
                                                    duration: 2000,
                                                    message: '撤销成功',
                                                    type: 'success'
                                                })
                                            }else{
                                                self.$message({
                                                    duration: 2000,
                                                    message: decodeURIComponent(res.msg),
                                                    type: 'error'
                                                })
                                            }
                                        })
            }
        }
    }
}
</script>

<style scoped >
#collectAll {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    width: 100%;
    height: auto;
    bottom: 0;
    top: 6rem;
    position: absolute;
}
.receiveitem{
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid #dfdfdf;
}
.userinfo{
    display:flex;
}
.receiveitem i{
    width:4rem;
    height:4rem;
    display:block;
}
.receiveitem p{
    height:4rem;
    line-height:2rem;
    margin-left:1rem;
    display: flex;
    align-items: center;
    text-align: left;
}
.receiveitem i img{
    width:100%;
    height:100%;
    border-radius:5rem;
}
.icons{
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.icons a{
    display: flex;
    flex-direction: column;
}
.icons a i,.icons a label{
    height:1.2rem;
    line-height:1.2rem;
}
</style>
